import java.awt.Polygon;
import java.awt.Rectangle;
import java.util.ArrayList;


public class Sensor {

	Polygon poly;
	
	public Sensor(Polygon poly){
		this.poly = poly;
	}
	
	public double checkProximity(ArrayList<Rectangle> _obstacleList, double _x, double _y, double _angle){
		Polygon poly2 = new Polygon(poly.xpoints,poly.ypoints,poly.npoints);

		for(int i = 0; i < poly2.npoints;i++){
			double x = poly2.xpoints[i];
			double y = poly2.ypoints[i];
			
			double x2 = x*Math.cos(_angle) - y*Math.sin(_angle);
			double y2 = y*Math.cos(_angle) + x*Math.sin(_angle);
			
			poly2.xpoints[i] = (int)x2;
			poly2.ypoints[i] = (int)y2;
		}		
		
		poly2.translate((int)_x, (int)_y);
		
		
		for(int i = 0; i < _obstacleList.size();i++){
			if(poly2.intersects(_obstacleList.get(i))){
				return 1.0d;
			}
		}
		return 0.0d;
	}
}
